package tbdp.tool;

import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import tbdp.tool.common.ColumnDesc;
import tbdp.tool.util.GsonUtils;

/**
 * @author xbkaishui
 * @version $Id: SchemaDump.java, v 0.1 2017-06-25 下午2:49 xbkaishui Exp $$
 */
public class SchemaDump {

    public static void main(String[] args) {

        String sampleFile = "/Users/xbkaishui/work/topcj/data-export/reader-hbase/src/test/resources/sample";
        List<ColumnDesc> cols = new ArrayList<>();

        try (InputStream ins = new FileInputStream(new File(sampleFile))) {
            List<String> lines = IOUtils.readLines(ins, "UTF-8");
            for (String line : lines) {
                String pair[] = line.split("＝");
                String key = pair[0].trim();
                ColumnDesc col = new ColumnDesc();
                col.setColumn(key);
                cols.add(col);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println(GsonUtils.toJson(cols));
    }
}
